package com.cci.kangdao.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cci.kangdao.crmapi.CRMHttpClientUtil;
import com.cci.kangdao.utilTool.MailUtil;
import com.cci.kangdao.utilTool.MailUtilException;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.cci.kangdao.service.ActivateIOSTimerService;
import com.cci.kangdao.utilTool.ParameterTool;
/**
 * 
 *服务技师出发到服务完成过程相关操作
 */
@Controller
public class ActivateIOSTimerController {
	private Logger log = Logger.getLogger(this.getClass().getName());
	@Autowired
	private ActivateIOSTimerService activateIOSTimerService;
	
	
	//通过服务技师userid获取该服务技师名下所有服务中的工单id
	@RequestMapping("/getInServiceOrderListByUserId.aspx")
	public ModelAndView getInServiceOrderListByUserId(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return activateIOSTimerService.getInServiceOrderListByUserId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}	
	
	
	//服务技师用户名和token绑定
	@RequestMapping("/userNameBindingToToken.aspx")
	public ModelAndView userNameBindingToToken(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return activateIOSTimerService.userNameBindingToToken(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	//服务技师用户名和token解绑
	@RequestMapping("/userNameUnBindingToToken.aspx")
	public ModelAndView userNameUnBindingToToken(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return activateIOSTimerService.userNameUnBindingToToken(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	@RequestMapping("motest.aspx")
	@ResponseBody
	public String test() throws MessagingException, UnsupportedEncodingException {
//		JSONObject jsonObject = CRMHttpClientUtil.httpPOSTRequest("https://sdflsjdfljsdflsjdfld", new HashMap<>(), new HashMap<>());
//		System.out.println(jsonObject.toString());
		//测试发邮件
		MailUtilException.sendMail("test", "test", "XCEC");
        MailUtil.sendMail("tb102@cummins.com", "test", "XCEC");
		return "";
	}
}
